package com.htandroid.htandroid.webservice;

import android.util.Xml;

import com.htandroid.htandroid.entity.UffjqgdList_detail;

import org.xmlpull.v1.XmlPullParser;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;

public class XMLQgdDjdetail {

    /**
     * 解析评论xml信息
     *
     * @param result
     * @return
     */
    public static ArrayList<UffjqgdList_detail> paraseCommentInfors(String result) {
        ArrayList<UffjqgdList_detail> list = new ArrayList<UffjqgdList_detail>();
        //字符转换成字节流
        InputStream inputStream = new ByteArrayInputStream(result.getBytes());
        XmlPullParser parser = Xml.newPullParser();

        try {
            parser.setInput(inputStream, "UTF-8");
            int eventType = parser.getEventType();
            UffjqgdList_detail info = new UffjqgdList_detail();

            while (eventType != XmlPullParser.END_DOCUMENT) {
                switch (eventType) {
                    case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理
                        break;
                    case XmlPullParser.START_TAG:// 开始元素事件
                        String name = parser.getName();
                        if (name.equalsIgnoreCase("UffjqgdList_detail")) {
                            info = new UffjqgdList_detail();
                        } else {
                            eventType = parser.next();
                        }
                        if (name.equalsIgnoreCase("cvouchid")) {
                            info.setCvouchid(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cinvcode")) {
                            info.setCinvcode(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cinvname")) {
                            info.setCinvname(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cinvstd")) {
                            info.setCinvstd(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cinvm_unit")) {
                            info.setCinvm_unit(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cinva_unit")) {
                            info.setCinva_unit(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("iinvexchrate")) {
                            info.setIinvexchrate(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("binvtype")) {
                            info.setBinvtype(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cinvaddcode")) {
                            info.setCinvaddcode(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("ddate_dh")) {
                            info.setDdate_dh(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("inum")) {
                            info.setInum(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("isnum")) {
                            info.setIsnum(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("iquantity")) {
                            info.setIquantity(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("iqgq")) {
                            info.setIqgq(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("iprice")) {
                            info.setIprice(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("iamount")) {
                            info.setIamount(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cvencodep1")) {
                            info.setCvencodep1(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cvennamep1")) {
                            info.setCvennamep1(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cvencodep2")) {
                            info.setCvencodep2(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cvennamep2")) {
                            info.setCvennamep2(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cvencodep3")) {
                            info.setCvencodep3(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cvennamep3")) {
                            info.setCvennamep3(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("ipricep1")) {
                            info.setIpricep1(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("ipricep2")) {
                            info.setIpricep2(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("ipricep3")) {
                            info.setIpricep3(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cchecker")) {
                            info.setCchecker(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("ccheckdate")) {
                            info.setCcheckdate(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cdisapprovereason")) {
                            info.setCdisapprovereason(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cvencode")) {
                            info.setCvencode(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cvenname")) {
                            info.setCvenname(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cdefine1")) {
                            info.setCdefine1(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cdefine2")) {
                            info.setCdefine2(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cdefine3")) {
                            info.setCdefine3(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("iinvsprice")) {
                            info.setIinvsprice(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cdefine4")) {
                            info.setCdefine4(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("bapprove")) {
                            info.setBapprove(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("qgdsid")) {
                            info.setQgdsid(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("inorder")) {
                            info.setInorder(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("bclose")) {
                            info.setBclose(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("djtype")) {
                            info.setDjtype(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("djcvencode")) {
                            info.setDjcvencode(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("djprice")) {
                            info.setDjprice(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("canupdjxy")) {
                            info.setCanupdjxy(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("succount")) {
                            info.setSuccount(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("ddate")) {
                            info.setDdate(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("ilprice")) {
                            info.setIlprice(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("clvencode")) {
                            info.setClvencode(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("ilquantity")) {
                            info.setIlquantity(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("avgiquantity")) {
                            info.setAvgiquantity(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cvencode1")) {
                            info.setCvencode1(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("avgiprice1")) {
                            info.setAvgiprice1(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("cvencode2")) {
                            info.setCvencode2(string2null(parser.getText()));
                        } else if (name.equalsIgnoreCase("avgiprice2")) {
                            info.setAvgiprice2(string2null(parser.getText()));
                        }
                        break;
                    case XmlPullParser.END_TAG:// 结束元素事件
                        if (parser.getName().equalsIgnoreCase("UffjqgdList_detail")) {
                            list.add(info);
                            info = null;
                        }
                        break;
                }
                eventType = parser.next();
            }
            inputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }

}  
